package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface DishMapper {

    /**
     * 根据分类id查询菜品数量
     *
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    /**
     * @MethodName: insert
     * @Author 冰白寒祭
     * @Description: 插入菜品数据
     * @Date: 2023/9/1  9:45
     * @param: Dish dish
     */
    @AutoFill(value = OperationType.INSERT)
    void insert(Dish dish);

    /**
     * @MethodName: pageQuery
     * @Author 冰白寒祭
     * @Description: 菜品分页查询
     * @Date: 2023/9/1 14:30
     * @param: DishPageQueryDTO dishPageQueryDTO
     * @return: Page<DishVO>
     */
    Page<DishVO> pageQuery(DishPageQueryDTO dishPageQueryDTO);

    /**
     * @MethodName: getById
     * @Author 冰白寒祭
     * @Description: 根据id查询菜品
     * @Date: 2023/9/1 15:18
     * @param: Long id
     * @return: Dish
     */

    @Select("select * from dish where id = #{id}")
    Dish getById(Long id);

    /**
     * @MethodName: deleteById
     * @Author 冰白寒祭
     * @Description: 根据id删除菜品
     * @Date: 2023/9/1 0001 21:27
     * @param: Long id
     */

    @Delete("delete from dish where id = #{id}")
    void deleteById(Long id);

    /**
     * @MethodName: update
     * @Author 冰白寒祭
     * @Description: 根据id动态修改菜品数据
     * @Date: 2023-09-01 23:06:57
     * @param: Dish dish
     */
    @AutoFill(value = OperationType.UPDATE)
    void update(Dish dish);

    /**
     * @MethodName: list
     * @Author 冰白寒祭
     * @Description: 动态条件查询菜品
     * @Date: 2023-09-02 08:58:14
     * @param: Dish dish
     * @return: List<Dish>
     */
    List<Dish> list(Dish dish);

    /**
     * @MethodName: getBySetmealId
     * @Author 冰白寒祭
     * @Description: 根据套餐id查询菜品
     * @Date: 2023-09-02 12:09:24
     * @param: id
     */

    @Select("select a.* from dish a left join setmeal_dish b on a.id = b.dish_id where b.setmeal_id = #{id}")
    List<Dish> getBySetmealId(Long id);

    /**
     * 根据条件统计菜品数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);
}
